<?php


/**
 * 支付宝app支付
 */




//发起支付
use Alipay\EasySDK\Kernel\Config;
use Alipay\EasySDK\Kernel\Factory;
public static function getOptions()
{
    $options = new aliConfig();
    $options->protocol = 'https';
    $options->gatewayHost = 'openapi.alipay.com';
    $options->signType = 'RSA2';

    $conf = Config::get('alipay', []);
    if (empty($conf)){
        return [];
    }

    $options->appId = $conf['appId'];

    // 为避免私钥随源码泄露，推荐从文件中读取私钥字符串而不是写入源码中
    $options->merchantPrivateKey = $conf['merchantPrivateKey'];

    //注：如果采用非证书模式，则无需赋值上面的三个证书路径，改为赋值如下的支付宝公钥字符串即可
    $options->alipayPublicKey = $conf['alipayPublicKey'];

    //可设置异步通知接收服务地址（可选）
    $options->notifyUrl = sys_config('site_url').$conf['notifyUrl'];

    //可设置AES密钥，调用AES加解密相关接口时需要（可选）
//        $options->encryptKey = "aa4BtZ4tspm2wnXLb1ThQA==";
    return $options;
}
$conf = AliPayService::getOptions();
if (empty($conf)){
    throw new \Exception('支付宝配置不存在');
}
Factory::setOptions($conf);
$result = Factory::payment()->app()->pay("付费会员服务", $order['order_id'], $order['price']);
return app('json')->successful(['order_info'=>$result]);

//支付回调
use Alipay\EasySDK\Kernel\Factory;
$conf = AliPayService::getOptionss();
if (empty($conf)){
    throw new \Exception('配置不存在');
}
Factory::setOptions($conf);
$notify_data = $_POST;
$verify = Factory::payment()->common()->verifyNotify($notify_data);
if($verify){
    Log::error('支付验证通过');
    if ($notify_data['trade_status'] == 'TRADE_SUCCESS'){
        $res = (new UpgradeTeamService())->upgradeTeam($notify_data['out_trade_no'],2);
        if ($res == true){
            echo 'success';
            Log::error('success');
        }else{
            echo 'fail';
        }
    }else{
        echo 'fail';
    }
}else{
    Log::error('支付宝回调验证失败,回调参数：');
    Log::error($notify_data);
    echo 'fail';
}